const cloud = require('wx-server-sdk')

cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()
const dishesCate = cloud.database().collection("dishes-category");
const dishesData = cloud.database().collection("dishes-data");
exports.main = async (event, context) => {
    let { data } = await dishesData.get({})
    let arr = []
    let obj = {}
    data.forEach(item => {
        let { category, cid, ...rest } = item
        if (!obj[cid]) {
            obj[cid] = { category, cid, data: [] }
        }
        obj[cid].data.push(rest)
    })
    let list = Object.values(obj)
    return {
        data: list
    }

}